﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wimm.Common.Entities;
using Wimm.Common.Entities.Utils;
using Wimm.Common.Interfaces.Utils;
using Windows.UI.Xaml;

namespace Wimm.Common.Entities.Utils
{
    public class PagedGridData<DalClass, CurClass> : IPagedGridData<DalClass, CurClass>
    {
      
        private PagedGridData(PagingFunctionSource<DalClass, CurClass> pagingFunctionSource, int itemsOnPage, bool isPagingEnabled)
        {
            ItemsList = new ObservableCollection<CurClass>();
            Source = pagingFunctionSource;
            IsPagingEnabled = isPagingEnabled;
            ItemsOnPage = itemsOnPage;
        }

        public PagedGridData(Func<IPagedRequest<DalClass>, Task<IPagedResult<CurClass>>> func, bool isPagingEnable = false) :
            this(new PagingFunctionSource<DalClass, CurClass>(func), 10, isPagingEnable)
        {
        }

        public bool IsPagingEnabled { get; protected set; }

        public PagingFunctionSource<DalClass, CurClass> Source { get; protected set; }

        public int ItemsOnPage { get; protected set; }

        public ObservableCollection<CurClass> ItemsList { get; protected set; }

        #region INotifyPropertyChanged

	    public void OnPropertyChanged(string args)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(args));
        }

        public event PropertyChangedEventHandler PropertyChanged;

	    #endregion    
    }
}
